home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-25 | 3.9 KB | 149 lines | [TEXT/CWIE] |
- #include "FinderFun.h"
-
- #define kFinderType 'FNDR'
- #define kFinderSignature 'MACS'
- #define kWhoCares '????'
-
-
- static void FinderFile(AEEventID finderAction);
-
- // Used as an object specifier for the current selection
- static long gSelectionAEData[] =
- {
- 4, 0 ,'form','enum',
- 4,'prop','want','type',
- 4,'prop','seld','type',
- 4,'sele','from','null',
- 0
- };
-
-
- /* leonardr [022599]
- A routine to determine the process serial number of the Finder. It returns the result as a
- parameter passed by reference. It also has a Boolean parameter which specifies whether or not
- the returned process serial number will represent the Finder process serial number as
- "kCurrentProcess" if it is the current process to allow a shortcut of the _GetNextEvent call
- dependencies of processing an AppleEvent.
-
- Input: shortcut - allow "kCurrentProcess" to be used if we are in the current process.
- Input: *finderpsn - result ProcessSerialNumber passed by reference.
-
- Output: error code that occured.
- */
-
-
- OSErr GetFinderProcess (ProcessSerialNumber *finderpsn, Boolean shortcut)
- {
- Boolean result;
- ProcessSerialNumber psn, currentpsn;
- ProcessInfoRec pir;
-
- psn.highLongOfPSN = 0;
- psn.lowLongOfPSN = kNoProcess;
- pir.processInfoLength = sizeof(ProcessInfoRec);
- pir.processName = nil; // don't want these bits of information
- pir.processAppSpec = nil;
-
- while (GetNextProcess(&psn) == noErr)
- {
- if (GetProcessInformation(&psn, &pir) == noErr)
- {
- if ((pir.processType == kFinderType) && (pir.processSignature == kFinderSignature))
- {
- if (shortcut && (GetCurrentProcess(¤tpsn) == noErr) &&
- (SameProcess(¤tpsn, &psn, &result) == noErr) && result)
- { // use the current process to shortcut the event dispatching
- finderpsn->highLongOfPSN = 0;
- finderpsn->lowLongOfPSN = kCurrentProcess;
- }
- else
- {
- *finderpsn = psn; // found the Finder's psn
- }
- return(noErr); // got the process serial number
- }
- }
- }
-
- return(procNotFound); // got an error - not found
- }
-
- //•••••••• Move File ••••••••
- void MoveFileToTrash (void)
- {
- FinderFile(kAEMove);
- }
-
- //•••••••• Finder File ••••••••
- static void FinderFile(AEEventID finderAction)
- {
- AEDesc AEFinderAddress;
- AppleEvent theEvent;
- ProcessSerialNumber finderPSN;
-
- GetFinderProcess (&finderPSN, true);
- if (!AECreateDesc(typeProcessSerialNumber, (Ptr)&finderPSN, sizeof(ProcessSerialNumber), &AEFinderAddress))
- {
- if (!AECreateAppleEvent(kAECoreSuite, finderAction, &AEFinderAddress, kAutoGenerateReturnID,
- kAnyTransactionID, &theEvent))
- {
- // Source
- FSSpec DocSpec;
- short vRefNum;
- long dirID;
- OSErr error;
-
- // No source files specified, use current selection
- AEPutParamPtr(&theEvent, (finderAction == kAECreateElement) ? 'to ' : keyDirectObject,
- cObjectSpecifier,(Ptr)&gSelectionAEData,sizeof(gSelectionAEData));
-
- // Destination
-
-
- error = FindFolder(-1, kTrashFolderType, true, &vRefNum, &dirID);
-
- error = FSMakeFSSpec(vRefNum, dirID, "\p", &DocSpec);
-
- if (error == noErr)
- {
- AliasHandle docAlias;
-
- if (!NewAlias(0,&DocSpec,&docAlias))
- {
- HLock((Handle)docAlias);
-
- AEPutParamPtr(&theEvent,keyAEInsertHere,typeAlias,(Ptr)*docAlias,GetHandleSize((Handle)docAlias));
-
- DisposeHandle((Handle)docAlias);
- }
- }
-
- // Specify to replace existing files
- // AEBuildParameters(&theEvent, "alrp:exsi");
- AEPutParamPtr(&theEvent,'alrp','true',0,0); // leonardr [061699]: try a valid value ;)
-
- // Send the message
- error = AESend(&theEvent, nil, kAENoReply, kAENormalPriority, 60, nil, nil);
- // SendAppleEvent(&theEvent, blockScript);
- }
-
- AEDisposeDesc(&AEFinderAddress);
- }
- }
-
- // 730, 340
- void ClickOnIcon(Point inPoint)
- {
- OSErr error;
-
- LMSetMouseLocation(inPoint);
-
- error = PostEvent(mouseDown, 0);
- ThrowIfOSErr_(error);
-
- LMSetMouseLocation(inPoint);
-
- error = PostEvent(mouseUp, 0);
- ThrowIfOSErr_(error);
- }
-